//
$.when($.ready).done(function(){
    //
    console.log(/\d+[a-z]+/.exec("123abc123def"));
    console.log(/(\d+[a-z]+)/.exec("123abc123def"));

    //console.log(/(\d+[a-z]+)/g.exec("123abc123def"));
    //console.log(/(\d+[a-z]+)/.exec("123abc123def"));
    //console.log("123abc123def".match(/(\d+[a-z]+)/g));
    //console.log("123abc123def".match(/(\d+[a-z]+)/));
    //
});
//
new Vue({
    el: "#visit_detail",
    data() {
        return {
            visiter_info: null, //访问者信息
            /*  */
            BorwseLogInfo: {
                page: 1,
                pageSize: 10,
                userid: '', //用户id
                visit_userid: '' //被访者id
            },
            /*  */
            shareLogInfo: {
                page: 1,
                pageSize: 10,
                share_userid: ""
            },
            /*  */
            contentIndex: 0,
            /*  */
            tabContentData: [{
                    name: '访问分析',
                    id: '0',
                    emptyWord: '~暂无访问分析记录~',
                    showListEmpty: false,
                    data: [], //列表数据
                    reqFnName: 'getUserBorwseLogInfo', //获取列表数据方法名
                    page: 1, //页码
                    pageSize: 10 //每页条数
                },
                {
                    name: '关系追踪',
                    id: '1',
                    emptyWord: '~暂无关系追踪记录~',
                    showListEmpty: false,
                    data: [], //列表数据
                    reqFnName: 'getShareLog', //获取列表数据方法名
                    page: 1, //页码
                    pageSize: 10 //每页条数
                }
            ],
            mescroll: null
        };
    },
    created() {
        //
        return;
        //
        this.visiter_info = $.parseJSON($.cookie("vmx-visiter-info20200628"));
        //
        this.$set(this.visiter_info, "visit_name", "");
        this.$set(this.visiter_info, "visit_count", 0);
        this.$set(this.visiter_info, "instime", this.dateFormatYMDHM2(this.visiter_info.instime));
        //
        console.log(this.visiter_info);
        //
        this.$set(this.BorwseLogInfo, "userid", this.visiter_info.userid);
        this.$set(this.BorwseLogInfo, "visit_userid", this.visiter_info.visit_userid);
        //
        this.$set(this.shareLogInfo, "share_userid", this.visiter_info.userid);
    },
    mounted() {
        //
        fe.setRem();
        //
        fe.openLoad.afterImgsLoaded(function() {

        });
        //
        //this.initMescroll();
    },
    methods: {
        //获取用户浏览信息数据
        getUserBorwseLogInfo() {
            //
            this.$set(this.BorwseLogInfo, "page", this.tabContentData[this.contentIndex * 1].page);
            //
            return new Promise((resolve, reject) => {
                this.$http({
                    url: '/getUserBorwseLogInfo',
                    method: 'post',
                    data: this.BorwseLogInfo
                }).then(data => {
                    console.log(data);
                    if (data.code == '1') {
                        this.$set(this.visiter_info, "visit_count", data.body.visit_count);
                        if (data.body.data.length) {
                            data.body.data.forEach(item => {
                                item.insTime = this.dateFormatYMDHM2(item.insTime);
                                if (item.type == '0') {
                                    item.type_value = this.visiter_info.nickname + '进行了' + item.type_value;
                                }
                                if (item.type == '1') {
                                    item.type_value = this.visiter_info.nickname + '查看了' + item.type_value;
                                }
                                this.tabContentData[this.contentIndex * 1].data.push(item)
                            });
                            this.tabContentData[this.contentIndex * 1].page++
                        }
                        //
                        if (!data.body.data.length && this.tabContentData[this.contentIndex * 1].page == 1) {
                            this.tabContentData[this.contentIndex * 1].showListEmpty = true
                        }
                        //
                        this.mescroll.endBySize(data.body.data.length, data.body.visit_count * 1); //必传参数(当前页的数据个数, 总数据量)
                        //
                        resolve();
                    } else {
                        vant.Toast.fail({
                            message: data.msg
                        });
                        reject(data.msg);
                    }
                }).catch(err => {
                    vant.Toast.fail({
                        message: '获取访问分享数据失败'
                    });
                    reject('获取访问分享数据失败');
                });
            });
        },
        //获取追踪记录数据
        getShareLog() {
            //
            this.$set(this.shareLogInfo, "page", this.tabContentData[this.contentIndex * 1].page);
            //
            return new Promise((resolve, reject) => {
                this.$http({
                    url: '/getShareLog',
                    method: 'post',
                    data: this.shareLogInfo
                }).then(data => {
                    console.log(data);
                    if (data.code == '1') {
                        if (data.body.data.length) {
                            data.body.data.forEach(item => {
                                item.insTime = this.dateFormatYMDHM2(item.insTime);

                                this.tabContentData[this.contentIndex * 1].data.push(item)
                            });
                            this.tabContentData[this.contentIndex * 1].page++
                        }
                        //
                        if (!data.body.data.length && this.tabContentData[this.contentIndex * 1].page == 1) {
                            this.tabContentData[this.contentIndex * 1].showListEmpty = true
                        }
                        //
                        this.mescroll.endBySize(data.body.data.length, data.body.visit_count * 1); //必传参数(当前页的数据个数, 总数据量)
                        //
                        resolve();
                    } else {
                        vant.Toast.fail({
                            message: data.msg
                        });
                        reject(data.msg);
                    }
                }).catch(err => {
                    vant.Toast.fail({
                        message: '获取追踪记录数据失败'
                    });
                    reject('获取追踪记录数据失败');
                });
            });
        },
        //
        initMescroll() {
            this.mescroll = new MeScroll("body", { //id固定"body"
                down: {
                    auto:false,
                    callback: mescroll => {
                        //console.log(mescroll);
                        this.tabContentData[this.contentIndex * 1].page = 1;
                        this.tabContentData[this.contentIndex * 1].data = null;
                        this.tabContentData[this.contentIndex * 1].data = [];
                        //
                        this[this.tabContentData[this.contentIndex * 1].reqFnName].bind(this)();
                    }
                },
                //上拉加载的配置项
                up: {
                    callback: this[this.tabContentData[this.contentIndex * 1].reqFnName].bind(this), //上拉回调,此处可简写; 相当于 callback: function (page) { getListData(page); }
                    noMoreSize: 5, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
                    empty: {
                        //icon: "../res/img/mescroll-empty.png", //图标,默认null
                        tip: "~~暂无更多数据哦~~", //提示
                        //btntext: "去逛逛 >", //按钮,默认""
                        // btnClick: function(){//点击按钮的回调,默认null
                        // 	alert("点击了按钮,具体逻辑自行实现");
                        // } 
                    },
                    //clearEmptyId: "dataList", //相当于同时设置了clearId和empty.warpId; 简化写法;默认null; 注意vue中不能配置此项
                    toTop: { //配置回到顶部按钮
                        src: "./img/employee--top-arrow.png", //默认滚动到1000px显示,可配置offset修改
                        //html: null, //html标签内容,默认null; 如果同时设置了src,则优先取src
                        offset: 780
                    },
                    lazyLoad: {
                        use: true
                    }
                }
            });
        },
        //切换
        changeTabContent(index) {
            this.contentIndex = index;
            this.tabContentData.forEach(item => {
                item.data.splice(0, item.data.length);
                item.page = 1;
            });
            //
            //this.mescroll.resetUpScroll();
            this.mescroll.destroy();
            this.mescroll = null;
            this.initMescroll();
        }
    }
})